<!DOCTYPE html>
<meta charset="utf-8">
<style>
.axis path, .axis line {
  fill: none;
  stroke: #000;
  shape-rendering: crispEdges;
}
</style>
<body>
<script src="../../d3.js"></script>
<script>
//svg宽，高
var width = 1000,height = 500;

//自定义时间格式化
var customTimeFormat = d3.time.format.multi([
  [".%L", function(d) { return d.getMilliseconds(); }],
  [":%S", function(d) { return d.getSeconds(); }],
  ["%I:%M", function(d) { return d.getMinutes(); }],
  ["%I %p", function(d) { return d.getHours(); }],
  ["%a %d", function(d) { return d.getDay() && d.getDate() != 1; }],
  ["%b %d", function(d) { return d.getDate() != 1; }],
  ["%B", function(d) { return d.getMonth(); }],
  ["%Y", function() { return true; }]
]);

//时间比例尺
var timeScale = d3.time.scale()
    .domain([new Date(2015, 0, 1), new Date(2016, 0, 1)])
    .range([0, width-40]);
	
timeScale.tickFormat([8],"%Y"); 
//添加时间轴    
var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height)
  .append("g")
    .attr("class", "axis")
    .attr("transform", "translate(" + 20 + "," + height/2 + ")")
    .call(d3.svg.axis().scale(timeScale).tickFormat(customTimeFormat).orient("bottom"));

</script>
